package com.bprogram.config;

import com.bprogram.dto.MyRabbitMq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitMqConfig {

    public static Channel getChannel() throws IOException, TimeoutException {
        //创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(MyRabbitMq.HOST);
        factory.setPort(MyRabbitMq.PORT);
        factory.setUsername(MyRabbitMq.USERNAME);
        factory.setPassword(MyRabbitMq.PASSWORD);
        //创建连接
        Connection connection = factory.newConnection();
        //创建信道
        return connection.createChannel();
    }
}
